const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  // 将年月日通过map方法执行补0处理函数,并用join方法用-符号隔开
  return [year, month, day].map(formatNumber).join('-')
  // return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()  //转换为字符串格式
  return n[1] ? n : '0' + n  //n[1]判断字符串是否有第二位数,有的话直接返回,没有的话补0
}
// 导出
module.exports = {
  formatTime
}
